home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / mui / mui-tools / multiuser / src / support / makekeyfiles.c < prev    next >
C/C++ Source or Header  |  1995-03-09  |  4KB  |  132 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Make the .MultiUser.keyfiles                                        *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <proto/intuition.h>
  16. #include <libraries/multiuser.h>
  17. #include <stdlib.h>
  18.  
  19. #include "MakeKeyfiles_rev.h"
  20.  
  21. #include "Locale.h"
  22.  
  23. char __VersTag__[] = VERSTAG;
  24.  
  25.  
  26. int __saveds Start(char *arg)
  27. {
  28.     struct ExecBase *SysBase;
  29.     struct DosLibrary *DOSBase;
  30.     struct IntuitionBase *IntuitionBase;
  31.     struct RDArgs *args;
  32.     LONG argarray[] = {
  33.         NULL, NULL, NULL
  34.     };
  35.     int rc = RETURN_ERROR;
  36.     int error;
  37.     BPTR passwddirlock, configdirlock, fl, fh;
  38.     struct DevProc *passwddirdp, *configdirdp, *devproc;
  39.     STRPTR *volume;
  40.     char key[64];
  41.     char buffer1[1024];
  42.     char buffer2[1024];
  43.     int i, j;
  44.     BOOL passwddirok = FALSE, configdirok = FALSE, ok = TRUE;
  45.     LONG stream[3];
  46.     ULONG seconds, micros;
  47.  
  48.     SysBase = *(struct ExecBase **)4;
  49.  
  50.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  51.          (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37)))) {
  52.         rc = ERROR_INVALID_RESIDENT_LIBRARY;
  53.         goto Exit;
  54.     }
  55.  
  56.     args = ReadArgs("PASSWDDIR/A,CONFIGDIR/A,VOLUME/A/M", argarray, NULL);
  57.     if (!args)
  58.         PrintFault(IoErr(), NULL);
  59.     else {
  60.         if (passwddirlock = Lock((STRPTR)argarray[0], ACCESS_READ)) {
  61.             if (configdirlock = Lock((STRPTR)argarray[1], ACCESS_READ)) {
  62.                 passwddirdp = GetDeviceProc((STRPTR)argarray[0], NULL);
  63.                 configdirdp = GetDeviceProc((STRPTR)argarray[1], NULL);
  64.                 CurrentTime(&seconds, µs);
  65.                 srand(micros);
  66.                 for (i = 0; i < 64; i++)
  67.                     key[i] = (char)(((ULONG)rand()>>25)+32);
  68.                 stream[0] = (LONG)key;
  69.                 volume = (STRPTR *)argarray[2];
  70.                 for (i = 0; volume[i] && ok; i++) {
  71.                     if (fl = Lock(volume[i], ACCESS_READ)) {
  72.                         devproc = GetDeviceProc(volume[i], NULL);
  73.                         if (passwddirdp->dvp_Port == devproc->dvp_Port) {
  74.                             NameFromLock(passwddirlock, buffer1, 1024);
  75.                             passwddirok = TRUE;
  76.                         } else
  77.                             buffer1[0] = '\0';
  78.                         for (j = 0; buffer1[j] && (buffer1[j] != ':'); j++);
  79.                         stream[1] = (LONG)&buffer1[j];
  80.                         if (configdirdp->dvp_Port == devproc->dvp_Port) {
  81.                             NameFromLock(configdirlock, buffer2, 1024);
  82.                             configdirok = TRUE;
  83.                         } else
  84.                             buffer2[0] = '\0';
  85.                         for (j = 0; buffer2[j] && (buffer2[j] != ':'); j++);
  86.                         stream[2] = (LONG)&buffer2[j];
  87.                         fl = CurrentDir(fl);
  88.                         error = 0;
  89.                         if (fh = Open(muKey_FileName, MODE_NEWFILE)) {
  90.                             if (VFPrintf(fh, "%s\n%s\n%s\n", stream) == -1)
  91.                                 error = IoErr();
  92.                             Close(fh);
  93.                         } else
  94.                             error = IoErr();
  95.                         if (error) {
  96.                             VPrintf(GetLocStr(MSG_KEYFILEFAIL), (LONG *)&volume[i]);
  97.                             PrintFault(error, " ");
  98.                         }
  99.                         UnLock(CurrentDir(fl));
  100.                         FreeDeviceProc(devproc);
  101.                     } else {
  102.                         PrintFault(IoErr(), NULL);
  103.                         ok = FALSE;
  104.                     }
  105.                 }
  106.                 if (ok)
  107.                     if (passwddirok)
  108.                         if (configdirok) {
  109.                             PutStr(GetLocStr(MSG_KEYFILEBACKUP));
  110.                             rc = RETURN_OK;
  111.                         } else
  112.                             PutStr(GetLocStr(MSG_BADCONFIGDIR));
  113.                     else
  114.                         PutStr(GetLocStr(MSG_BADPASSWDDIR));
  115.                 FreeDeviceProc(configdirdp);
  116.                 FreeDeviceProc(passwddirdp);
  117.                 UnLock(configdirlock);
  118.             } else
  119.                 PrintFault(IoErr(), NULL);
  120.             UnLock(passwddirlock);
  121.         } else
  122.             PrintFault(IoErr(), NULL);
  123.     }
  124.     FreeArgs(args);
  125.  
  126. Exit:
  127.     CloseLibrary((struct Library *)IntuitionBase);
  128.     CloseLibrary((struct Library *)DOSBase);
  129.  
  130.     return(rc);
  131. }
  132.